package com.ada.lbs.webservice.v2;

import java.io.IOException;

import com.ada.http.Connection;
import com.ada.http.HttpConnection;
import com.ada.http.Connection.Method;
import com.ada.lbs.webservice.domain.BackSuggestion;
import com.google.gson.Gson;

public class SuggestionService {

	private String suggestion = "http://api.map.baidu.com/place/v2/suggestion";
	private String region;

	public static void main(String[] args) {
		SuggestionService s=new SuggestionService();
		//s.region="西安";
		BackSuggestion ss=	s.searchByCircle("汽车");
		System.out.println(ss);
	}

	public BackSuggestion searchByCircle(String keyword) {
		BackSuggestion reult = null;
		Connection connection = HttpConnection.connect(suggestion);
		connection.data("q", keyword);
		// json或xml
		connection.data("output", "json");
		// connection.data("tag", keyword); 日式烧烤/铁板烧、朝外大街
		// 检索结果详细程度。取值为1 或空，则返回基本信息；取值为2，返回检索POI详细信息
		connection.data("region", "" + region);

		connection.data("ak", ServiceConfig.ak);
		connection.method(Method.GET);
		try {
			String back = connection.execute().body();
			System.out.println(back);
			Gson gson = new Gson();
			reult = gson.fromJson(back, BackSuggestion.class);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return reult;

	}
}
